﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using Equation.Enterprise.Utilities.DesignByContract;
using MvcContrib.Pagination;
using ENail.Domain.Core;
using Equation.Enterprise.Framework.Web.Model;

namespace ENail.Portal.Web.Models
{
    public class EmployeeListViewItem : BaseViewModel<Int16>
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Phone { get; set; }
        public double CommisionPercentage { get; set; }
    }

    public class EmployeeListViewModelMapper : ListViewModelMapper<EmployeeListViewItem, Employee>
    {
        public static readonly int PageSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get("PAGE_SIZE"));
        public static readonly int DefaultPage = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get("DEFAULT_PAGE"));

        public override void MapDomainToView(List<Employee> domainModel, GenericListViewModel<EmployeeListViewItem> viewModel)
        {
            Check.Require(domainModel != null);
            Check.Require(viewModel != null);

            viewModel.List = (from e in domainModel
                              select new EmployeeListViewItem
                              {
                                  Id = e.Id,
                                  FirstName = e.FirstName,
                                  LastName = e.LastName,
                                  Phone = e.Phone,
                                  CommisionPercentage = e.CommisionPercentage
                              }
                   ).OrderBy(x => x.FirstName).AsPagination(viewModel.Page ?? DefaultPage, PageSize);
        }

        public override void MapViewToDomain(GenericListViewModel<EmployeeListViewItem> viewModel, List<Employee> domainModel)
        {
            throw new NotImplementedException();
        }
    }
}